package com.atguigu.controller;
import com.atguigu.cache.ShopCache;
import com.atguigu.entity.*;
import com.atguigu.search.Product;
import com.atguigu.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/**
 * <p>
 * 基本销售属性表 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/sku")
@Api(tags = "sku 详情接口")
public class SkuDetailController {
    @Resource
    private SkuDetailService skuDetailService;
    @Resource
    private BaseCategoryViewService baseCategoryViewService;
    @Resource
    private SkuInfoService skuInfoService;
    @Resource
    private ProductSalePropertyValueService productSalePropertyValueService;

    @GetMapping("getSkuInfo/{skuId}")
    @ApiOperation("根据skuId查询 sku的基本信息")
    @ShopCache(prefix = "skuInfo")
    public SkuInfo getSkuInfo(@PathVariable Long skuId){

        return skuDetailService.getSkuInfo(skuId);
    }
    @GetMapping("getCategoryView/{category3Id}")
    @ApiOperation("根据分类category3Id查询 商品的分类信息")
    public BaseCategoryView getCategoryView(@PathVariable("category3Id") Long category3Id){
        //因为该表 id 就是 category3Id
        return baseCategoryViewService.getById(category3Id);
    }
    @GetMapping("getSkuPrice/{skuId}")
    @ApiOperation("根据skuId查询 商品的实时价格")
    public BigDecimal getSkuPrice(@PathVariable("skuId") Long skuId){
        SkuInfo skuInfo = skuInfoService.getById(skuId);
        return skuInfo.getPrice();
    }
    //d.销售属性id的组合与skuId的对应关系
    @GetMapping("getSalePropertyAndSkuIdMapping/{productId}")
    @ApiOperation("销售属性组合id 和skuId的对应关系")
    public Map<Object,Object> getSalePropertyIdAndSkuIdMapping(@PathVariable("productId") Long productId){
         Map<Object,Object> objectMap= productSalePropertyValueService.getSalePropertyIdAndSkuIdMapping(productId);
         return objectMap;
    }
    @GetMapping("getSpuSalePropertyAndSelected/{productId}/{skuId}")
    @ApiOperation("获取所有销售属性 spu和一份sku 对应的销售属性")
    public List<ProductSalePropertyKey> getSpuSalePropertyAndSelected(@PathVariable("productId") Long productId,@PathVariable("skuId") Long skuId){
        List<ProductSalePropertyKey>  productSalePropertyValues=productSalePropertyValueService.getSpuSalePropertyAndSelected(productId,skuId);
        return productSalePropertyValues;
    }
}


